package com.hy.study.driver;

import com.hy.study.bean.FlowBean;
import com.hy.study.mapper.FlowCountMapper;
import com.hy.study.partition.ProvincePartitioner;
import com.hy.study.reduce.FlowCountReducer;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

/**
 * @author huyong
 * @date 2024 年 01 月 29 日 16:55: 38
 */
public class FlowCountDriver {
    public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException {
        final String inputfile = "F:\\study\\Hadoop\\input\\phone_data\\phone_data.txt";
        final String outputfile = "F:\\study\\Hadoop\\output\\phone_result";
        Configuration conf = new Configuration();
        Job job = Job.getInstance(conf);
        job.setJarByClass(FlowCountDriver.class);
        job.setMapperClass(FlowCountMapper.class);
        job.setReducerClass(FlowCountReducer.class);
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(FlowBean.class);
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(FlowBean.class);
        //指定分区的规则 这里是自定义的
        job.setPartitionerClass(ProvincePartitioner.class);
        //这里指定分区是需要5个
        job.setNumReduceTasks(5);
        FileInputFormat.addInputPath(job, new Path(inputfile));
        FileOutputFormat.setOutputPath(job, new Path(outputfile));

        boolean completion = job.waitForCompletion(true);
        System.exit(completion ? 0 : 1);

    }
}
